package com.peng.ivos.dict.controller;

import com.peng.ivos.base.response.JsonResult;
import com.peng.ivos.dict.pojo.dto.DictQuery;
import com.peng.ivos.dict.pojo.dto.DictSaveParam;
import com.peng.ivos.dict.service.DictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 字典控制层
 * @author： Peng
 * @date： 2024/5/27
 * @version: 1.0
 */
@RestController
@RequestMapping("/v1/dict")
@Slf4j
public class DictController {
    @Autowired
    private DictService dictService;

    @GetMapping("/select")
    public JsonResult getDictByExample(DictQuery dictQuery){
        log.debug("字典列表查询参数，dictQuery:{}", dictQuery);
        return JsonResult.success("分页查询成功", dictService.getDictByExample(dictQuery));
    }

    @PostMapping("/save")
    public JsonResult saveDict(DictSaveParam dictSaveParam){
        log.debug("字典保存参数，dictSaveParam:{}", dictSaveParam);
        return dictService.saveDict(dictSaveParam);
    }

    @PostMapping("/delete/{id}")
    public JsonResult deleteDict(@PathVariable("id") Long id){
        log.debug("字典删除参数，id:{}", id);
        return dictService.deleteDict(id);
    }
}
